package com.myzhouye.biz.bean;/***
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.myzhouye.biz.model.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @program: game01
 * @description: 登录对象
 * @author: 那条蠢鱼
 * @create: 2025-11-05 16:51
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginUser implements UserDetails {
    private Long userId;          // 用户ID（关联User.id）
    private String username;      // 用户名（登录账号）
    private String nickname;      // 用户昵称（展示用）
    private Collection<? extends GrantedAuthority> authorities; // 用户权限
    @JsonIgnore  // 关键：序列化时忽略此字段，避免写入 Token
    private String password;

    public LoginUser(User user) {
        this.userId = user.getId();
        this.username = user.getUsername();
        this.nickname = user.getNickname();
        this.password = user.getPassword(); // 仅用于认证，不随 Token 存储
    }

    // UserDetails接口默认实现（无需修改）
    @Override
    public String getPassword() { return password; }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() { return true; }
    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() { return true; }
    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() { return true; }
    @Override
    @JsonIgnore
    public boolean isEnabled() { return true; }
}
